//
//  UserInfoManager.m
//  jiyujiaProgram
//
//  Created by Jame on 15/11/25.
//  Copyright © 2015年 中良 赵. All rights reserved.
//

#import "UserInfoManager.h"

@implementation UserInfoManager
singleton_implementation(UserInfoManager);

-(void)saveUserInfoToSanbox{
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults setObject:self.user forKey:USER];
    [defaults setObject:self.password forKey:PWD];
    [defaults setBool:self.autoLogin forKey:AUTOLOGIN];
    [defaults setObject:self.lat forKey:LAT];
    [defaults setObject:self.lng forKey:LNG];
    NSData *member = [NSKeyedArchiver archivedDataWithRootObject:self.memberModel];
    [defaults setObject:member forKey:MEMBERINFO];
    NSData *teacher = [NSKeyedArchiver archivedDataWithRootObject:self.teacherModel];
    [defaults setObject:teacher forKey:TEACHERINFO];
    [defaults synchronize];
}

-(void)loadUserInfoFromSanbox{
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSData *member = [defaults objectForKey:MEMBERINFO];
    NSData *teacher = [defaults objectForKey:TEACHERINFO];
    self.memberModel = [NSKeyedUnarchiver unarchiveObjectWithData:member];
    self.teacherModel = [NSKeyedUnarchiver unarchiveObjectWithData:teacher];
    self.user = [defaults objectForKey:USER];
    self.password = [defaults objectForKey:PWD];
    self.autoLogin = [defaults boolForKey:AUTOLOGIN];
    self.lat = [defaults objectForKey:LAT];
    self.lng = [defaults objectForKey:LNG];
}


-  (void)updateLocationWithLat:(NSString *)lat WithLng:(NSString *)lng
{
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults setObject:lat forKey:LAT];
    [defaults setObject:lng forKey:LNG];
    [defaults synchronize];
}


@end
